package cn.piesat.sport.domain;

import com.fasterxml.jackson.annotation.JsonInclude;

@JsonInclude(JsonInclude.Include.NON_NULL)
public class Response {

	private static final String OK = "ok";
	private static final String ERROR = "error";

	private Result result;
	private Object data;

	private Response() {
		this.data=null;
	}

	private static final Response single = new Response();

	public static Response getInstance() {
		single.data=null;
		return single;
	}

	public Response success() {
		this.result = new Result(true, OK);
		return this;
	}

	public Response success(Object data) {
		this.result = new Result(true, OK);
		this.data = data;
		return this;
	}

	public Response failure() {
		this.result = new Result(false, ERROR);
		return this;
	}

	public Response failure(String message) {
		this.result = new Result(false, message);
		return this;
	}

	public Result getResult() {
		return result;
	}

	public Object getData() {
		return data;
	}

	public class Result {

		private boolean success;
		private String message;

		public Result(boolean success) {
			this.success = success;
		}

		public Result(boolean success, String message) {
			this.success = success;
			this.message = message;
		}

		public boolean isSuccess() {
			return success;
		}

		public String getMessage() {
			return message;
		}
	}
}